<?php

namespace App\Http\Controllers\Home;

use App\Services\Home\MaproomService;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;

class MaproomController extends Controller
{
    protected $service;

    public function __construct(MaproomService $maproomService)
    {
        $this->service = $maproomService;
    }

    /**
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
     * 地图找房
     */
    public function mapFindingRoom()
    {
        return view(env('DEFAULT_TEMPLATE').'.maproom');
    }

    /**
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     * 获取区域及楼盘信息
     */
    public function getMapRoomData(Request $request)
    {
        // 获取区域(县级单位或区域)
        return $this->service->getMaproomDataByCityId($request->all());
    }

    /**
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     * 未选择区域时获取所有楼盘 未分页 地图上显示
     */
    public function getMapRoomAllData(Request $request)
    {
        // 获取区域(县级单位或区域)楼盘信息
        return $this->service->getMaproomAllDataByCityId($request->all());
    }

    /**
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     * 获取当前市和区域/县、物业类型
     */
    public function initArea(Request $request)
    {
        $city_id = $request->input('city_id')??0;
        return $this->service->initAreaByCityId($city_id);
    }
}
